package com.xique.park.controller.client.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.park.controller.client.web.bean.request.ClientOprGateRequest;
import com.xique.park.controller.client.web.service.biz.service.IClientCommandService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: caogq
 * @Date: 2021/7/31 10:21
 * @Description:
 */
@Controller
public class ClientCommandController extends BaseController {

    @Autowired
    private IClientCommandService clientCommandService;

    /**
     * 道闸控制（开闸）
     * @return
     */
    @PostMapping("/openGate")
    @ResponseBody
    @ApiOperation("开闸")
    @Log(title = "开闸", businessType = BusinessType.COMMAND)
    public AjaxResult openGate(@Validated  @RequestBody ClientOprGateRequest request){
        return AjaxResult.success(clientCommandService.openGate(request));
    }

    /**
     * 道闸控制（关闸）
     * @return
     */
    @PostMapping("/closeGate")
    @ResponseBody
    @ApiOperation("关闸")
    @Log(title = "关闸", businessType = BusinessType.COMMAND)
    public AjaxResult closeGate(@Validated @RequestBody ClientOprGateRequest request){
        return AjaxResult.success(clientCommandService.closeGate(request));
    }

    /**
     * 设备抓拍图片
     * @return
     */
    @PostMapping("/trigPic")
    @ResponseBody
    @ApiOperation("抓拍图片")
    @Log(title = "抓拍图片", businessType = BusinessType.COMMAND)
    public AjaxResult trigPic(@RequestBody String sn){
        if (StringUtils.isEmpty(sn)){
            return AjaxResult.error("设备编号不能为空");
        }
        return clientCommandService.trigPic((String)JSONObject.parseObject(sn).get("sn"));
    }
}
